package net.lzzy.practices.web.handler;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @author liaodcc.
 */
@ControllerAdvice
public class PracticeExceptionHandler {
    @ExceptionHandler
    public ModelAndView handleBusinessException(HttpServletRequest request,BusinessException e){
        String errInfo = "业务异常:" + e.getErrInfo();
        ModelAndView mv = new ModelAndView();
        mv.addObject("title",errInfo);
        mv.addObject( "url",request.getRequestURI().toString());
        mv.addObject("exception",e);
        mv.setViewName("error/error");
        return mv;
    }
    @ExceptionHandler(Exception.class)
    public ModelAndView handleExcrption(HttpServletRequest request,Exception e){
            ModelAndView mv = new ModelAndView();
            mv.addObject( "title", "非业务异常");
            mv.addObject("url", request.getRequestURI().toString());
            mv.addObject("exception", e);
            mv.setViewName("error/error");
            return mv;
        }
}
